<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use app\index\controller\Basecontroller;

class Allproject extends Basecontroller
{

  public function Navselect(){
  
  $nowjson = getPost();

      $res = db('classify')->select();
    
    return res(1001, '拿到分类表的全部数据',$res);

  }
  public function StateNav(){
  
  $nowjson = getPost();
   
      $res = db('goods_state')->select();
    
    return res(1001, '拿到项目状态表的全部数据',$res);

  }
  public function Selectgoods(){
  
    $res = db()->query("select * from gjc_goods");
        // $res = db('goods')->select();
      
      return res(1001, '拿到商品表的全部数据',$res);
  
    }
    public function Selectlikegoods(){
  
      // $nowjson = getPost();
  
      // select * from gjc_goods order by rand()
      $res = db()->query("select * from gjc_goods order by rand() limit 0,4");
          // $res = db('goods')->select();
        
        return res(1001, '拿到猜您喜欢去拿到商品表的全部数据',$res);
    
      }

    public static function Searchcontent(){

      $nowIDjson = json_decode(file_get_contents("php://input"), true);
      if(!empty($nowIDjson)){

        $serchdata = $nowIDjson['serchdata'];
        $keyword = explode(" ",$serchdata);
        $whereArry = [];
        foreach($keyword as $value){
          $whereArry[] = ['like','%'.$value.'%'];
        }
        $whereArry[] = 'or';
      }else{
        $whereArry = ['like','%%'];
      }
      $where['g_name|g_text'] = $whereArry;
      
      $result = Db::table('gjc_goods')
      ->where($where)
      ->select();
      return res(1001, '寻找搜索数据成功', $result);
      
    }
    //通过导航栏的id拿到数据回页面打印
    public function SearchNav(){
      $nowjson = getPost();

     

      if(!empty($nowjson)){
        
        $where = [
          'cid' => $nowjson['serchdata']
        ];
  
        $result = db('goods')->where($where)->select();
        return res(1001, '通过导航条id寻找数据成功', $result);

      }
  
    


    
    }
      //通过导航栏的状态拿到数据id,之后拿到对应的数据

      public function Searchavstate(){

        $nowjson = getPost();
  
        $where = [
          'State' => $nowjson['serchdata']
        ];
      
    
        $res = db('goods_state')->where($where)->find();
        if ($res) {

          

          $where = [

            'g_state' =>  $res["s_id"]
          ];

          $result = db('goods')->where($where)->select();

          return res(1001, '通过导航条状态查找数据成功', $result);
        }
    }
    
      //点击最新上架，拿到最新的前8条
      public function getNewGoods(){

        $nowjson = getPost();
        $serchdata= $nowjson['serchdata'];
        // if($serchdata == 0){
        //   $res = db('goods')
        //   ->field('gid , g_picture ,g_name ,g_start_money ,g_end_money')
        //   ->limit(0, 8)
        //   ->where(['g_state' => $serchdata])
        //   ->order('g_create_time desc')
        //   ->select();
        // }else if($serchdata == 5){
              
        //   $res = db('goods')
        //   ->field('gid , g_picture ,g_name ,g_start_money ,g_end_money')
        //   ->limit(0, 8)
        //   ->where(['g_state' => $serchdata])
        //   ->order('g_create_time asc')
        //   ->select();
          
        // }
        // return res(1002, '点击停止众筹，拿到最新的前8条', $res);
          if($serchdata == 0){
            $res = db('goods')
              ->field('gid , g_picture ,g_name ,g_start_money ,g_end_money')
              ->limit(0, 8)
              ->where(['g_state' => $serchdata])
              ->order('g_create_time desc')
              ->select();
              return res(1001, '点击最新上架，拿到最新的前8条', $res);
          }
          $res = db('goods')
          ->field('gid , g_picture ,g_name ,g_start_money ,g_end_money')
          ->limit(0, 8)
          ->where(['g_state' => $serchdata])
          ->order('g_create_time asc')
          ->select();
          return res(1001, '点击停止众筹，拿到最新的前8条', $res);



      }
      //
      //侧导航栏的拿到数据回到页面打印
      
    public function Sidenavselect(){

      $result = db('classify')->select();
    
      return res(1001, '拿到分类表的全部数据',$result);
    }
    //侧导航栏的id拿到数据回到页面打印

    public function SearchsideNav(){

      $nowjson = getPost();
      if(!empty($nowjson)){
        
      $where2 = [
        'cid' => $nowjson['serchdata']
      ];

      $result = db('goods')->where($where2)->select();

      // var_dump( $result);
      // var_dump(656555);
      // var_dump(99999);

      return res(1001, '通过侧导航条id寻找数据成功', $result);

      }

   

  }

    


}